<template>
  <!-- 新增登记 -->
  <section class="piao-box">
    <div class="flex-gutter">
      <div class="flex-left">
        <div class="form-tool" style="align-items: center;">
          <h3>患者信息</h3>
          <div>
            <!-- <el-form :inline="true" @submit.native.prevent="getPatientDetail('init')">
            <el-form-item>
              <el-input v-model="medicalCardCode" placeholder="请输入医疗卡号"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button icon="el-icon-search" type="primary" native-type="submit" circle></el-button>
            </el-form-item>
            </el-form>-->
          </div>
        </div>
        <div class="form-tool">
          <div>
            <el-form label-width="100px" label-position="top" ref="form" :model="form" :rules="rules">
              <el-row :gutter="10">
                <el-col :span="8">
                  <el-form-item label="患者：" prop="patientId">
                    <el-select
                      v-model.trim="form.patientId"
                      allow-create
                      default-first-option
                      filterable
                      remote
                      clearable
                      @clear="onClearPatient"
                      :remote-method="getPatient"
                      @change="onChangePatient"
                    >
                      <el-option
                        v-for="(item, index) in patientArray"
                        :key="index"
                        :value="item.patientId"
                        :label="item.name + '（' + item.mobil + '）'"
                      ></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="16">
                  <el-form-item label="证件号：" prop="idCard">
                    <el-input v-model="form.idCard" @blur="onBlurIdCard">
                      <el-select v-model="form.certificateType" style="width:100px;" slot="prepend" placeholder="请选择">
                        <el-option v-for="(item, index) in certificateTypeArray" :key="index" :label="item.desc" :value="item.id"></el-option>
                      </el-select>
                    </el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="出生年月：" prop="birthday">
                    <el-date-picker v-model="form.birthday" value-format="yyyy-MM-dd" type="date" @change="onChangeBirthday"></el-date-picker>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="年龄：" prop="age">
                    <el-input v-model="form.age"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="性别：" prop="sex">
                    <el-radio-group v-model="form.sex">
                      <el-radio :label="1">男</el-radio>
                      <el-radio :label="2">女</el-radio>
                    </el-radio-group>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="手机号：" prop="mobile">
                    <el-input v-model="form.mobile"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="国籍：" prop="nationalityId">
                    <el-select v-model="form.nationalityId">
                      <el-option v-for="(item, index) in nationalityEnum" :key="index" :value="item.id" :label="item.desc"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="省市区：" prop="areaArray">
                    <!-- <v-area v-model="form.areaArray" :isFull="true"></v-area> -->
                    <cascaderCity v-model="form.areaArray"></cascaderCity>
                  </el-form-item>
                </el-col>
                <el-col :span="24">
                  <el-form-item label="详细地址：" prop="address">
                    <el-input v-model="form.address"></el-input>
                  </el-form-item>
                </el-col>
                <!-- <el-col :span="8">
                  <el-form-item label="病人卡号：" prop="medicalCardCode">
                    <el-input v-model="form.medicalCardCode"></el-input>
                  </el-form-item>
                </el-col>-->
                <!-- <el-col :span="6">
              <el-form-item label="来源：" prop="sourceId">
                <el-select v-model="form.sourceId" clearable>
                  <el-option v-for="(item,index) in sourceArray" :key="index" :value="item.id" :label="item.desc"></el-option>
                </el-select>
              </el-form-item>
                </el-col>-->
                <el-col :span="8">
                  <el-form-item label="民族：" prop="nationId">
                    <el-select v-model="form.nationId" clearable>
                      <el-option v-for="(item, index) in nationArray" :key="index" :value="item.id" :label="item.desc"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="邮箱：" prop="email">
                    <el-input v-model="form.email"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="婚姻状况：" prop="isMarried">
                    <el-radio-group v-model="form.isMarried">
                      <el-radio :label="1">已婚</el-radio>
                      <el-radio :label="0">未婚</el-radio>
                    </el-radio-group>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="职业：" prop="occupationId">
                    <el-select v-model="form.occupationId" clearable>
                      <el-option v-for="(item, index) in occupationArray" :key="index" :value="item.id" :label="item.desc"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="工作单位：" prop="workUnit">
                    <el-input v-model="form.workUnit"></el-input>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <!-- <el-form-item label="推荐来源：" prop="source">
                    <el-select
                      v-model="form.source"
                      clearable
                      :popper-append-to-body="false"
                      @change="onChangeTJ"
                    >
                      <el-option
                        v-for="item in sourceArray"
                        :key="item.id"
                        :value="item.desc"
                        :label="item.desc"
                      ></el-option>
                    </el-select>
                  </el-form-item> -->
                  <el-form-item label="推荐来源：" prop="sourceType">
                    <el-select v-model="form.sourceType" clearable :popper-append-to-body="false" @change="onChangeTJ">
                      <el-option v-for="item in sourceArray" :key="item.id" :value="item.id" :label="item.desc"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="16">
                  <el-form-item label="推荐详情：" prop="sourceName" :rules="[{ required: true, message: '此项必填', trigger: 'change' }]">
                    <doctorSearch v-if="form.sourceType == 1" ref="tjDoc" :pageSize="20" v-model="form.sourceCode" @change="onTCDoctor"></doctorSearch>
                    <el-select
                      v-else-if="form.sourceType == 2 || form.sourceType == 3 || form.sourceType == 4"
                      value-key="id"
                      v-model="sourceObj"
                      placeholder="请选择"
                      @change="onChangeSourceObj"
                    >
                      <el-option v-for="item in sourceObjList" :key="item.id" :label="item.name" :value="item"></el-option>
                    </el-select>
                    <!-- <el-select v-else-if="form.source == '平台宣传'" filterable allow-create v-model="form.sourceName" placeholder="请选择">
                      <el-option v-for="(item, index) in ptEnum" :key="index" :label="item.desc" :value="item.desc"></el-option>
                    </el-select>-->
                    <el-input v-else v-model="form.sourceName"></el-input>
                  </el-form-item>
                </el-col>
                <!-- <el-col :span="8">
                  <el-form-item label="备注：" prop="desc">
                    <el-input v-model="form.desc"></el-input>
                  </el-form-item>
                </el-col>-->
              </el-row>
              <h3>科室信息</h3>
              <el-row :gutter="10">
                <el-col :span="8">
                  <el-form-item label="科室：" prop="deptId">
                    <deptSearch v-model="form.deptId" @change="onChangeDept"></deptSearch>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="类型：" prop="registerType">
                    <el-select v-model="form.registerType" clearable>
                      <el-option v-for="(item, index) in reserveTypeArray" :key="index" :value="item.id" :label="item.desc"></el-option>
                    </el-select>
                  </el-form-item>
                </el-col>
                <el-col :span="8">
                  <el-form-item label="医生：" prop="doctorId">
                    <doctorSearchDay ref="doctorSearch" v-model="form.doctorId" :deptId="form.deptId" @change="onChangeDoctor"></doctorSearchDay>
                  </el-form-item>
                </el-col>
                <el-col v-show="form.doctorId" :span="16">
                  <el-form-item label="预约时间：" prop="dateDay" :rules="form.doctorId ? { required: true, message: '此项必填', trigger: 'blur' } : null">
                    <el-input @focus="onOpenYYTime" :value="form.dateDay + '  ' + form.yyTime"></el-input>
                  </el-form-item>
                </el-col>
              </el-row>
              <el-form-item label="预约内容：" prop="registerContent">
                <el-input v-model="form.registerContent"></el-input>
              </el-form-item>
              <div style="border-top:1px solid #eee;">
                <table border="0" width="100%">
                  <tr v-for="(item, index) in familyArray" :key="index" height="50">
                    <td>关系：{{ item.relation | changeAssist(relationEnum) }}</td>
                    <td>姓名：{{ item.name }}</td>
                    <td>性别：{{ item.sex | toSex }}</td>
                    <td>出生年月：{{ item.birthday }}</td>
                    <td>
                      年龄：
                      <span v-if="item.age > 18">{{ item.age }}</span>
                      <span v-else>{{ item.birthday | toTimeContrast }}</span>
                    </td>
                    <td>手机号：{{ item.mobile }}</td>
                    <td>
                      <el-link type="danger">
                        <i class="el-icon-delete" @click="onDelFamily(item, index)"></i>
                      </el-link>
                    </td>
                  </tr>
                </table>

                <br />
                <div>
                  <el-button @click="dialogFamily = true" icon="el-icon-circle-plus-outline" size="mini">添加家庭成员</el-button>
                </div>
                <br />
              </div>
              <el-form-item label>
                <el-button :disabled="!qxBtns.add" type="primary" style="width:100%" @click="onSubmit">保存</el-button>
              </el-form-item>
            </el-form>
          </div>
          <!-- <div>
        <div style="width:230px">
          <img v-if="form.head" :src="form.head|imageUrl" style="width:100%;height:230px;">
          <img v-else src="@/img/unknown-avatar.png" alt="" style="width:100%;height:230px;">
          <div style="margin-top:7px;">
            <oneImageUpload v-model="form.head" v-show="false" ref="oneImageUpload" @begin="upFileLoading=true" @success="upFileLoading=false"></oneImageUpload>
            <el-button @click="onOpenFile" :loading="upFileLoading" style="width:100%;">上传头像</el-button>
          </div>
        </div>
          </div>-->
        </div>
        <family v-model="dialogFamily" @success="onAddFamily"></family>
        <reserveTime v-model="dialogReserveTime" :doctorId="form.doctorId" :deptId="form.deptId" @confirm="onConfirmTime" type="dj"></reserveTime>
      </div>
      <div class="flex-right" v-loading="pageLoad" element-loading-background="rgba(0, 0, 0, 0.15)">
        <el-alert
          style="margin-bottom:15px;"
          title="温馨提示："
          type="info"
          show-icon
          description="通过预约挂号的患者将在此处展示，现场登记患者登记成功后，直接进入分诊界面，不在此列！"
        ></el-alert>
        <h3>今日患者</h3>
        <today></today>
      </div>
    </div>
  </section>
</template>
<script>
import validate from "@/_js/validate.js";
const initFormData = {
  email: "",
  name: "",
  registerType: "",
  registerContent: "",
  registerName: "",
  certificateType: 1,
  sourcePass: "",
  patientId: "",
  birthday: "",
  sourceId: "",
  age: "",
  source: "",
  sourceName: "",
  sourceCode: "",
  head: "",
  sex: 1,
  mobile: "",
  idCard: "",
  isMarried: 0,
  nationId: "",
  occupationId: "",
  workUnit: "",
  openId: "",
  provinceId: "",
  province: "",
  sourceType: "", //来源类型
  cityId: "",
  city: "",
  nationalityId: 1,
  districtId: "",
  district: "",
  address: "",
  type: 2,
  deptId: "",
  doctorId: "",
  dateDay: "",
  timeId: "",
  medicalCardCode: "",
  relationJSON: "",
  tjDoctorId: null,
  areaArray: [],
  yyTime: ""
};
export default {
  props: ["qxBtns"],
  components: {
    oneImageUpload: () => import("@/components/oneImageUpload.vue"),
    cascaderCity: () => import("@/components/cascaderCity.vue"),
    family: () => import("./family.vue"),
    reserveTime: () => import("@/pages/_com/reserveTime.vue"),
    deptSearch: () => import("@/pages/_com/deptSearch.vue"),
    doctorSearch: () => import("@/pages/_com/newSearchDoctor.vue"),
    doctorSearchDay: () => import("@/pages/_com/searchDocDay.vue"),
    patientSearch: () => import("@/pages/_com/patientSearch.vue"),
    today: () => import("./todayYYForToday.vue")
  },
  data() {
    return {
      dialogReserveTime: false,
      upFileLoading: false,
      dialogFamily: false,
      familyArray: [],
      relationEnum: [],
      //医疗卡号
      medicalCardCode: "",
      form: { ...initFormData },
      //身份证验证
      rulesIdCard: { validator: validate.vPeopleNumber, trigger: "blur" },
      rules: {
        birthday: [{ required: true, message: "此项必填", trigger: "change" }],
        age: [
          { required: true, message: "此项必填", trigger: "blur" },
          { validator: validate.integerNum, trigger: "blur" }
        ],
        patientId: [
          { required: true, message: "此项必填", trigger: "change" },
          { validator: validate.verigySpacing, trigger: ["change", "blur"] }
        ],
        mobile: [
          { required: true, message: "此项必填", trigger: "blur" },
          { validator: validate.vPhone, trigger: "blur" }
        ],
        medicalCardCode: [
          { validator: validate.NoHanZi, trigger: "blur" },
          { max: 30, message: "限制30位字符", trigger: "blur" }
        ],
        deptId: [{ required: true, message: "此项必填", trigger: "change" }],
        birthday: [{ required: true, message: "此项必填", trigger: "blur" }],
        registerType: [{ required: true, message: "此项必填", trigger: "change" }],
        // source: [
        //   {
        //     required: true,
        //     message: "请选择来源",
        //     trigger: "change"
        //   }
        // ],
        sourceType: [
          {
            required: true,
            message: "请选择来源",
            trigger: "change"
          }
        ]
      },
      pageLoad: false,
      //接诊类型
      reserveTypeArray: [],
      //职业
      occupationArray: [],
      //民族
      nationArray: [],
      //来源
      sourceArray: [],
      sourceObjList: [],
      sourceObj: null,
      //患者
      patientArray: [],
      //国籍
      nationalityEnum: [],
      //科室
      deptArray: [],
      //医生
      doctorArray: [],
      //机构推荐
      jgEnum: [],
      //平台宣传
      ptEnum: [],
      //证件类型
      certificateTypeArray: [],
      curItem: {
        patientInfo: {
          patientId: ""
        }
      },
      pager: { pageSize: 12, pageNum: 1, total: 0 },
      tableList: [],
      //预约状态
      triageStatusArray: []
    };
  },
  mounted() {
    let th = this;
    th.getCommonConfigByKey("国籍").then(res => {
      th.nationalityEnum = res;
    });
    th.getCommonConfigByKey("预约类型").then(res => {
      th.reserveTypeArray = res;
    });
    th.getCommonConfigByKey("推荐来源").then(res => {
      th.sourceArray = res;
    });
    th.getCommonConfigByKey("职业").then(res => {
      th.occupationArray = res;
    });
    th.getCommonConfigByKey("民族").then(res => {
      th.nationArray = res;
    });
    th.getCommonConfigByKey("患者关系").then(res => {
      th.relationEnum = res;
    });
    th.getCommonConfigByKey("证件类型").then(res => {
      th.certificateTypeArray = res;
    });
    th.getCommonConfigByKey("机构推荐").then(res => {
      th.jgEnum = res;
    });
    th.getCommonConfigByKey("平台宣传").then(res => {
      th.ptEnum = res;
    });
    th.getPatient();
  },
  methods: {
    //推荐医生
    onTCDoctor(obj) {
      const th = this;
      th.form.tjDoctorId = obj.id;
      th.form.sourceName = obj.trueName;
      th.form.sourceCode = obj.id;
    },
    onAddFamily(obj) {
      this.familyArray.push(obj);
    },
    onDelFamily(obj, index) {
      let th = this;
      if (obj.patientId) {
        th.$confirm(`确定删除吗?`, "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
          center: true
        })
          .then(() => {
            let j = {
              patientId: obj.patientId
            };
            th.showLoading(true);
            th.$api
              .deletePatientRelation(j)
              .then(res => {
                if (res.executed) {
                  th.$message.success("删除成功");
                  th.familyArray.splice(index, 1);
                } else {
                  th.$message.error(res.message);
                }
                th.showLoading(false);
              })
              .catch(() => {
                th.showLoading(false);
              });
          })
          .catch(() => {});
      } else th.familyArray.splice(index, 1);
    },
    //显示预约时间
    onOpenYYTime() {
      let th = this;
      if (th.form.deptId && th.form.doctorId) {
        th.$nextTick(function() {
          th.dialogReserveTime = true;
        });
      } else {
        th.$message.warning("请选择科室和医生");
      }
    },
    //清空预约时间
    onChangeDoctor(value) {
      let th = this;
      th.form.dateDay = "";
      th.form.timeId = "";
      th.form.yyTime = "";
    },
    //选择预约时间
    onConfirmTime(obj) {
      let th = this;
      th.form.dateDay = obj.dateStr;
      th.form.timeId = obj.id;
      th.form.yyTime = `${obj.startTime}~${obj.endTime}`;
      th.$refs["form"].validateField("dateDay");
    },
    onSubmit() {
      let th = this;
      let j = {};
      let fn = function() {
        th.showLoading();
        j.name = j.name.trim();
        th.$api.registerAddOrder(j).then(res => {
          if (res.executed) {
            th.$message.success("操作成功");
            th.formReset();
          } else {
            th.$message.error(res.message);
          }
          th.showLoading(false);
        });
      };
      th.$refs["form"].validate(v => {
        if (v) {
          Object.assign(j, th.form);
          if (th.familyArray.length == 0) j.relationJSON = "";
          else j.relationJSON = JSON.stringify(th.familyArray);
          delete j.areaArray;
          delete j.yyTime;
          //读取地区
          th.form.areaArray.forEach((item, index) => {
            switch (index) {
              case 0:
                j.provinceId = item.adcode;
                j.province = item.name;
                break;
              case 1:
                j.cityId = item.adcode;
                j.city = item.name;
                break;
              case 2:
                j.districtId = item.adcode;
                j.district = item.name;
                break;
            }
          });
          if (typeof th.form.patientId != "number") {
            j.patientId = "";
          }
          //获取预约类型名称
          let yyTypeData = th.reserveTypeArray.find(d => {
            return d.id == th.form.registerType;
          });
          if (yyTypeData) j.registerName = yyTypeData.desc;
          fn();
        }
      });
    },
    //清空患者
    onClearPatient() {
      this.getPatient();
      this.formReset();
    },
    //获取患者
    getPatient(name) {
      let th = this;
      let j = {
        hpId: th.adminUser.hpId,
        pageNum: 1,
        pageSize: 20,
        nameOrMobile: name
      };
      th.$api.getThePatientLibraryList(j).then(res => {
        if (res.executed) {
          th.patientArray = res.dataBody.list;
        }
      });
    },
    //根据年月算年龄
    onChangeBirthday() {
      let th = this;
      if (!th.form.birthday) return;
      th.form.age = th.$utils.getAgeToBirthday(th.form.birthday);
    },
    //读取身份证信息
    onBlurIdCard() {
      let th = this;
      if (!th.form.idCard) return;
      if (th.form.certificateType != 1) return;
      const fn = () => {
        let result = th.$utils.getIdCardInfo(th.form.idCard);
        th.form.birthday = result.birthday;
        th.form.sex = result.sex == "男" ? 1 : 2;
        //用户的生日
        th.form.age = th.$utils.getAgeToBirthday(result.birthday);
      };
      validate.vPeopleNumber(null, th.form.idCard, function(err) {
        if (typeof err == "undefined") {
          fn();
        }
      });
    },
    //上传头像
    onOpenFile() {
      let th = this;
      th.$refs["oneImageUpload"].openFile();
    },
    //获取患者详情
    getPatientDetail(obj) {
      let th = this;
      let j = {
        hpId: th.adminUser.hpId
      };
      if (obj == "init") {
        if (!th.medicalCardCode) {
          th.$message.warning("请输入卡号");
          return;
        }
        j.medicalCardCode = th.medicalCardCode;
      } else {
        j.patientId = th.form.patientId;
      }
      th.form.areaArray = [];
      th.$api.getThePatientLibraryById(j).then(res => {
        if (res.executed) {
          let data = res.thePatientLibraryDetail;
          th.$utils.joinFormJson(th.form, data);
          th.getFamilyUser(res.patientRelationList);
          this.revertSource(res.thePatientLibraryDetail);
          if (data.provinceId) {
            th.form.areaArray = [
              { name: data.province, adcode: data.provinceId },
              { name: data.city, adcode: data.cityId },
              { name: data.district, adcode: data.districtId }
            ];
          }
          if (obj == "init") {
            th.patientArray = [{ patientId: data.pnationId, name: data.name }];
          }
        } else {
          th.$message.error("查询失败了");
        }
      });
    },
    revertSource(data) {
      this.sourceObjList = [];
      this.sourceObj = null;
      this.getRecommendDetailListByType({ type: "revert" });
    },
    onChangeSourceObj(obj) {
      this.form.sourceName = obj.name;
      this.form.sourceCode = obj.id;
    },
    //科室选择
    onChangeDept(value) {
      let th = this;
      th.form.doctorId = "";
      th.$nextTick(function() {
        th.$refs["doctorSearch"].getData();
      });
    },

    //患者选择
    onChangePatient(value) {
      let th = this;
      console.log(value);
      if (!value) return;
      if (typeof value != "number") {
        th.formReset();
        th.$nextTick(function() {
          th.form.patientId = value;
          th.form.name = value;
        });
        return;
      }
      th.getPatientDetail();
    },
    //获取家庭成员
    getFamilyUser(list) {
      let th = this;
      if (!list) {
        th.familyArray = [];
        return;
      }
      let arr = [];
      list.forEach(item => {
        let j = {
          relation: "",
          name: "",
          sex: "",
          birthday: "",
          age: "",
          mobile: "",
          patientId: "",
          openId: ""
        };
        th.$utils.joinFormJson(j, item);
        arr.push(j);
      });
      th.familyArray = arr;
    },
    //重置表单
    formReset() {
      this.sourceObj = null;
      this.sourceObjList = [];
      this.$refs["form"].resetFields();
      this.form = { ...initFormData };
      setTimeout(() => {
        this.$refs["form"].clearValidate();
      }, 0);
      this.familyArray = [];
      this.onChangeDoctor();
    },
    //到诊
    onArrive(obj, index) {
      const th = this;
      // th.curItem = obj;
      th.$confirm("确定此患者已到诊吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true
      })
        .then(() => {
          th.showLoading();
          let j = {
            status: 6,
            id: obj.id
          };
          th.$api
            .updateRegisterRecord(j)
            .then(res => {
              if (res.executed) {
                th.$message.success("更新完成");
                // obj.status = j.status;
                th.tableList.splice(index, 1);
              } else {
                th.$message.error(res.message);
              }
              th.showLoading(false);
            })
            .catch(res => {
              th.showLoading(false);
            });
        })
        .catch(() => {});
    },
    //取消预约
    onCancel(obj, index) {
      let th = this;
      if (!th.qxBtns.del) {
        th.$message.warning("权限不足");
        return;
      }
      if (obj.status != 1) {
        th.$message.warning("无法取消");
        return;
      }
      th.$confirm(`确定取消吗?`, "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true
      })
        .then(() => {
          let j = {
            id: obj.id,
            cancelDesc: "工作人员取消"
          };
          th.showLoading();
          th.$api.registerCancelOrder(j).then(res => {
            if (res.executed) {
              th.$message.success("取消完成");
              th.tableList.splice(index, 1);
            } else {
              th.showLoading(false);
              th.$message.error(res.message);
            }
          });
        })
        .catch(() => {
          th.showLoading(false);
        });
    },
    onChangeTJ() {
      this.form.sourceName = "";
      this.form.sourceCode = "";
      this.form.tjDoctorId = null;
      this.getRecommendDetailListByType({ type: "init" });
    },
    getRecommendDetailListByType({ type }) {
      let params = {
        hpId: this.adminUser.hpId,
        type: ""
      };
      if (this.form.sourceType != 1 && this.form.sourceType != 5 && this.form.sourceType != 6) {
        params.type = this.form.sourceType;
      }
      // if (this.form.source == "机构推荐") {
      //   params.type = 2;
      // }
      // if (this.form.source == "平台宣传") {
      //   params.type = 3;
      // }
      // if (this.form.source == "活动宣传") {
      //   params.type = 4;
      // }
      if (params.type) {
        this.$api
          .getRecommendDetailListByType({
            ...params
          })
          .then(res => {
            if (res.executed) {
              this.sourceObjList = res.dataBody;
              this.sourceObj = null;

              if (type && type === "revert") {
                this.sourceObj = this.sourceObjList.filter(obj => obj.id == this.form.sourceCode)[0];
              } else {
                this.form.sourceName = "";
                this.form.sourceCode = "";
              }
            }
          });
      }
    },
    //判断类名
    classToName(type) {
      switch (type) {
        case 1:
          return "bg-yjz";
          break;
        case 2:
          return "bg-sy";
          break;
        case 3:
          return "bg-hong";
          break;
        case 4:
          return "bg-yqx";
          break;
        case 5:
          return "bg-jzz";
          break;
        default:
          return "bg-dfz";
          break;
      }
    }
  },
  watch: {}
};
</script>
<style lang="scss" scoped>
@import "../../_css/reserve.scss";
.flex-gutter {
  h3 {
    margin-top: 5px;
  }
  display: flex;
  .flex-left {
    width: 520px;
    flex-shrink: 0;
  }
  .flex-right {
    flex: 1;
    padding-left: 30px;
    width: 100%;
    position: relative;
    overflow: hidden;
    &::before {
      width: 1px;
      height: 100%;
      background: #eee;
      content: "";
      position: absolute;
      top: 0;
      left: 15px;
    }
  }
  .el-form-item {
    margin-bottom: 5px;
  }
}
</style>
